//
//  MapViewController.m
//  TravelDiary
//
//  Created by lanou3g on 15/11/11.
//  Copyright © 2015年 YDB MAC. All rights reserved.
//

#import "MapViewController.h"
#import "HomeCollectionViewCell.h"
#import "LocationViewController.h"
#import "PathViewController.h"
#import "SearchViewController.h"

@interface MapViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>
@property(nonatomic, strong)UICollectionView *mapHomeCollectionView;
@property(nonatomic,strong)UILabel *headerLabel;
@property(nonatomic, strong)UIImageView *headerImageView;
@property(nonatomic, strong)NSArray *imageViewArray;
@property(nonatomic, strong)NSArray *titleArray;
@property (nonatomic, strong) UIImageView *topView;
@end

@implementation MapViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createCollectionView];
    
    self.titleArray = @[@"位置",@"附近",@"导航",@"路线"];
    self.imageViewArray = @[@"weizhi",@"sousuo",@"daohang",@"luxian"];

}
-(void)createCollectionView{
    
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
    //改变每一个item大小
    flowLayout.itemSize = CGSizeMake(self.view.frame.size.width/2-60, self.view.frame.size.width/2-60);
    //改变上下行之间的间距
    flowLayout.minimumLineSpacing = 30;
    //改变两个itme中间的大小
    flowLayout.minimumInteritemSpacing = 10;
    //控制collectionView的itme距离上，左、下、右之间的距离
    flowLayout.sectionInset = UIEdgeInsetsMake(200, 40, 40, 40);
    
    _mapHomeCollectionView = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:flowLayout];
    _mapHomeCollectionView.delegate = self;
    _mapHomeCollectionView.dataSource = self;
    _mapHomeCollectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:_mapHomeCollectionView];
    
    [self.mapHomeCollectionView  registerClass:[HomeCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    

     _headerImageView = [[UIImageView alloc]init];
    _headerImageView.frame = CGRectMake(0,0, self.view.frame.size.width, 180);
    _headerImageView.image = [UIImage imageNamed:@"worldMap"];
    _headerImageView.backgroundColor = [UIColor greenColor];
    [_mapHomeCollectionView addSubview:_headerImageView];
    
}
//返回cell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return 4;

}
//返回cell
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    HomeCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    cell.titleLabel.text = _titleArray[indexPath.row];
    cell.iconImage.image = [UIImage imageNamed:_imageViewArray[indexPath.row]];
    return cell;

}
//collectionView点击方法
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    LocationViewController *loc = [[LocationViewController alloc]init];
    PathViewController *pat = [[PathViewController alloc]init];
    SearchViewController *search = [[SearchViewController alloc]init];
    
       switch (indexPath.row) {
        case 0:
            loc.titleStr = self.titleArray[indexPath.row];
            [self.navigationController showViewController:loc sender:self];
            
                      break;
        case 1:
            search.titleStr = self.titleArray[indexPath.row];
            [self.navigationController showViewController:search sender:self];
                      break;
        case 2:
            loc.titleStr = self.titleArray[indexPath.row];
            [self.navigationController showViewController:loc sender:self];
        
            break;
        case 3:
            pat.patStr = self.titleArray[indexPath.row];
            [self.navigationController showViewController:pat sender:self];
          
            break;
      
    }


}
- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
